$Title Test: One-HH illustration

$Offsymxref Offsymlist

Option MINLP = COUENNE;
Option Limrow=0, Limcol=0;
Option Solprint=Off;
$Offsymxref
$Offsymlist

$Ontext

This is a one-household model for illustration purpose. The construction of
this model is detailed in Ma_SE_Baseline.

$Offtext

****************Setup the village economy of five households ******************

Sets

h    Households
             /1/;

*************************Multipliers and endownments ***************************

Scalars

** All monetary values are measured in 1,000
** All labor measured in months and land in mu

n    No. households in the economy
     /1/

m    Capital multiplier
     /5/

a    Tech index for small farms
     /2.3/

a2   Tech index large farms
     /4.4/

k    Setup cost for small farms per mu
     /0.8/

k2   Setup cost for large farms per mu
     /1.1/

s0   HH contract land endowment
     /4.1/

l0   HH labor endowment in months of three laborers
     /14.1/

f    Multiplier for the minimum labor-month input to keep each unit of land
     /0.3/

rho  Multiplier for supervision labor-month
     /0.1/

int  Exogenous interest rate for deposit at the bank
     /0.004/

w   Nonfarm and farm wage rate
    /2.5/

r  Land rental rate
    /0.4/
;

********************************Capital endowment ******************************

Parameters

c(h) Capital endowment for each household;

$ Call gdxxrw C:/Users/ma155/Documents/gamsdir/projdir/Parameters_3/c_%instance%.xls par=c rng=Sheet1!A1 rdim=1
$ gdxin c_%instance%.gdx
$ Load  c
$ gdxin

Display c;

Parameters

v(h) Capital endowment for each household;

$ Call gdxxrw C:/Users/ma155/Documents/gamsdir/projdir/Parameters_3/v_13.xls par=v rng=Sheet1!A1 rdim=1
$ gdxin v_13.gdx
$ Load  v
$ gdxin

Display v;

***************************Target variables ************************************

Variables

einc      Economy-level total expected income to be maximized

inc(h)    HH expected income

pinc(h)   HH productive income

s(h)      HH cultivated size

s2(h)     HH cultivated size for large farms

lf(h)     HH labor farming

lf2(h)    HH labor farming for on large farms

hin(h)    HH hired-in farming labor

hin2(h)   HH hired-in farming labor for large farms

lg(h)     HH dummy variable equal one if a farm expands beyoud 30

md(h)     HH dummy variable equal one if a farm is s0-30 in size

ex(h)     HH dummy variable equal one if a hh reduces s(h) to zero
;

Positive variables
s, lf, hin, s2, lf2, hin2;

Binary variables
lg, md, ex;

***************************Target HH functions *********************************

Equations

Obj          Economy-level total expected income

Constr01(h)  HH income definition

Constr02(h)  HH productive income definition

Constr11(h)  Farming labor endowment constraint

Constr12(h)  Farming labor min constraint

Constr13(h)  Farming labor hire-in and wage earning constraint

Constr2(h)   Budget constraint

Constr31(h)  Farm type option 1

Constr32(h)  Farm type option 2

Constr33(h)  Farm type option 3

Constr41(h)  Farm type option size requirement 1

Constr42(h)  Farm type option size requirement 2

Constr43(h)  Farm type option size requirement 3

Constr44(h)  Farm type option size requirement 4

Constr45(h)  Farm type option size requirement 5

Constr46(h)  Farm type option size requirement 6

Constr47(h)  Farm type option size requirement 7;


* Computation of equations
* The obj function is the sum of household incomes

Obj..  einc =E= Sum(h,inc(h));

** HH income, incl the non-prod value of land
** To avoid unnecessary confusion and complexity,
** assume that wage pmt can be made by installments and does not affect
** int earnings from the bank
** Yet, wage pmt is contrained by the budget as all pmt must be done
** before sales. Similarly, wage inc does not become part of bank savings.

Constr01(h)..
inc(h) =E=

   w*(l0-lf(h)-rho*hin(h)) * (1-lg(h))
 + w*(l0-lf2(h)-rho*hin2(h)) * lg(h)

+ a*sqrt(lf(h)+hin(h))*sqrt(s(h))*(1-lg(h))
+ a2*sqrt(lf2(h)+hin2(h))*sqrt(s2(h))*lg(h)

+ v(h)*sqrt(lf(h)+hin(h))*sqrt(s(h)) * (1-md(h))
+ v(h)*sqrt((lf(h)+hin(h))/(0.01+s(h))*s0)*sqrt(s0) *  md(h)
+ v(h)*sqrt((lf2(h)+hin2(h))/(0.01+s2(h))*s0)*sqrt(s0) * lg(h)

- w*hin(h) * (1-lg(h))
- w*hin2(h) * lg(h)

- r*(s(h)-s0) * (1-lg(h))
- r*(s2(h)-s0) * lg(h)

- k*s(h) * (1-lg(h))
- k2*s2(h) * lg(h)

+ int* ( m * c(h)
- (r*(s(h)-s0) + k*s(h)) * (1-lg(h))
- (r*(s2(h)-s0) + k2*s2(h)) * lg(h)) ;

** HH productiion income

Constr02(h)..

pinc(h) =E=

w*(l0-lf(h)-rho*hin(h)) * (1-lg(h))
 + w*(l0-lf2(h)-rho*hin2(h)) * lg(h)

+ a*sqrt(lf(h)+hin(h))*sqrt(s(h))*(1-lg(h))
+ a2*sqrt(lf2(h)+hin2(h))*sqrt(s2(h))*lg(h)

- w*hin(h) * (1-lg(h))
- w*hin2(h) * lg(h)

- r*(s(h)-s0) * (1-lg(h))
- r*(s2(h)-s0) * lg(h)

- k*s(h) * (1-lg(h))
- k2*s2(h) * lg(h)

+ int* ( m * c(h)
- (r*(s(h)-s0) + k * s(h)) * (1-lg(h))
- (r*(s2(h)-s0) + k2 * s2(h)) * lg(h)) ;


** HH farming labor equals labor endowment minus other labor use

Constr11(h)..

(lf(h) + rho*hin(h)) * (1-lg(h))
+ (lf2(h) + rho*hin2(h) ) * lg(h)

=L= l0 ;

** HH farming labor no less than minimum requirement

Constr12(h)..

(lf(h)+ hin(h))* (1-lg(h))
+ (lf2(h)+ hin2(h))* lg(h) =G=
f*s(h) * (1-lg(h))
+ f*s2(h) * lg(h) ;

* HH cannot hire in and earn wages simultaneously

Constr13(h)..

(l0-lf(h)-rho*hin(h)) * hin(h)
+ (l0-lf2(h)-rho*hin2(h)) * hin2(h) =E= 0 ;


* Captial expenditure is constrained by the endowment

Constr2(h)..

(r*(s(h)-s0) + k*s(h) + w*hin(h)) * (1-lg(h))
+ (r*(s2(h)-s0) + k2*s2(h)+ w*hin2(h))* lg(h)
=L= m*c(h) ;

** Variables with "2" and those w/o "2" cannot co-exist

Constr31(h)..  s(h)*lg(h) + s2(h)*(1-lg(h)) =E= 0 ;

Constr32(h)..  lf(h)*lg(h) + lf2(h)*(1-lg(h)) =E= 0 ;

Constr33(h)..  hin(h)*lg(h) + hin2(h)*(1-lg(h)) =E= 0 ;

** Not allowing for s or s2=30 to avoid confusion

Constr41(h)..  (s(h)-29.99)*(1-lg(h)) =L= 0 ;

Constr42(h)..  (s2(h)-30.01)*lg(h) =G= 0 ;

* The smallest farming size is 1 unit

Constr43(h)..  s(h)*ex(h) =E= 0 ;

Constr44(h)..  (s(h)-1.01)*(1-ex(h)) =G= 0 ;

Constr45(h)..  (lf(h)+hin(h))*ex(h) =E= 0 ;

* The middle sized farms in s0-30

Constr46(h)..  (s(h) - s0 - 0.01)*(1 - md(h)) =L= 0 ;

Constr47(h)..  (s(h) - s0 - 0.01)*md(h) =G= 0 ;

******************************Define the model *********************************

Model Test /All/;

** Set initial values
lf.up(h)=3.484;
lf.lo(h)=3.465;

******************************Solve the model **********************************

* Solve mixed integer nonlinear program
Solve Test using MINLP maximizing einc;

* Export result to Excel
* Repeat the display of einc to make Exl format consistent
execute_unload 'HH-%instance%.gdx';
execute 'gdxxrw.exe HH-%instance%.gdx o=HH-%instance%.xls var=einc.l rng=A1 var=inc.l rng=A2 var=pinc.l rng=A4 var=s.l rng=A7 var=md.l rng=A9 var=s2.l rng=A11 var=lg.l rng=A13 var=lf.l rng=A15 var=lf2.l rng=A17 var=hin.l rng=A19 var=hin2.l rng=A21 var=einc.l rng=A23';




